package com.question_barrier.entity;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
 * user表实体
 */
@Data
@Entity
@Table(name = "user")
public class User implements Comparable<User> {

    @Id
    private long id;
    @Column(name = "open_id")
    private String openId;
    @ApiModelProperty("用户名")
    @Column(name = "name")
    private String name;
    @ApiModelProperty("用户积分")
    @Column(name = "integral")
    private long integral;
    @Column(name = "create_at")
    private Date createAt;
    @Column(name = "create_by")
    private long createBy;
    @Column(name = "update_at")
    private Date updateAt;
    @Column(name = "update_by")
    private long updateBy;
    @Column(name = "is_del")
    private byte isDel;
    @ApiModelProperty("用户头像url")
    @Column(name = "photo_url")
    private String photoUrl;

    public User() {
    }
    public User(long id, String openId, String name, long integral, Date createAt, long createBy, Date updateAt, long updateBy, byte isDel, String photoUrl) {
        this.id = id;
        this.openId = openId;
        this.name = name;
        this.integral = integral;
        this.createAt = createAt;
        this.createBy = createBy;
        this.updateAt = updateAt;
        this.updateBy = updateBy;
        this.isDel = isDel;
        this.photoUrl = photoUrl;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", openId='" + openId + '\'' +
                ", name='" + name + '\'' +
                ", integral=" + integral +
                ", createAt=" + createAt +
                ", createBy=" + createBy +
                ", updateAt=" + updateAt +
                ", updateBy=" + updateBy +
                ", isDel=" + isDel +
                ", photoUrl='" + photoUrl + '\'' +
                '}';
    }

    @Override
    public int compareTo(User u) {
        return (int) (u.getIntegral() - this.getIntegral());
    }

}
